package com.hh.bss.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Node {
	
	public String id;
	
	public String text;
	
	public String parentId;
	
	public int weight;
	
	public boolean visible =true;
	
	public Node parentNode;
	
	public Children children = new Children();
	
	public String toString(){
		if(visible){
			String result = "{"
					+"id: '" + id + "'"
					+", text:'" +text+"'";
			if(children !=null && children.getSize()!=0)
			{
				result +=",children:" +children.toString();
			} else {
				result +=", leaf:true";
			}
			return result + "}";		
     	} else {
     		return "";
     	}
	}
	
	public void sortChildren(){
		if(children !=null && children.getSize() !=0){
			children.sortChildren();
		}
		
	}
	
	public void initializeLeafList(List<Node> leafList) {
		if(children !=null ||children.getSize()==0){
			leafList.add(this);
		} else {
			children.initializeLeafList(leafList);
		}
	}
	
	public void setTreeNotVisible() {
		visible = false;
		if(children !=null && children.getSize() !=0){
			children.setTreeNotVisible();
		}
	}
	
	public void setRouteVisible(){
		visible  = true;
		for(Node parentNode = this.parentNode; parentNode !=null;parentNode = parentNode.parentNode){
			parentNode.visible = true;
		}
	}
	
	public void increaseRouteWeight(){
		weight++;
		updateNodeWeightToDB(this);
	}

	private void updateNodeWeightToDB(Node node) {
         //更新节点权值到数据库
	}
	
	public static void main(String[] args) {
		List dataList =new ArrayList();
		
		HashMap dataRecord1 = new HashMap();
		dataRecord1.put("id", "0");
		dataRecord1.put("text", "根");
		dataRecord1.put("parentId", "");
		dataRecord1.put("weight", "1");
		
		HashMap dataRecord2 = new HashMap();
		dataRecord2.put("id", "1");
		dataRecord2.put("text", "1");
		dataRecord2.put("parentId", "0");
		dataRecord2.put("weight", "1");
		
		HashMap dataRecord3 = new HashMap();
		dataRecord3.put("id", "2");
		dataRecord3.put("text", "2");
		dataRecord3.put("parentId", "0");
		dataRecord3.put("weight", "1");
						
		HashMap dataRecord4 = new HashMap();
		dataRecord4.put("id", "3");
		dataRecord4.put("text", "3");
		dataRecord4.put("parentId", "0");
		dataRecord4.put("weight", "1");
						
		HashMap dataRecord5 = new HashMap();
		dataRecord5.put("id", "4");
		dataRecord5.put("text", "4");
		dataRecord5.put("parentId", "0");
		dataRecord5.put("weight", "1");
		
		HashMap dataRecord6 = new HashMap();
		dataRecord6.put("id", "11");
		dataRecord6.put("text", "11");
		dataRecord6.put("parentId", "1");
		dataRecord6.put("weight", "1");
		
		HashMap dataRecord7 = new HashMap();
		dataRecord7.put("id", "12");
		dataRecord7.put("text", "12");
		dataRecord7.put("parentId", "1");
		dataRecord7.put("weight", "1");
		
		HashMap dataRecord8 = new HashMap();
		dataRecord8.put("id", "21");
		dataRecord8.put("text", "21");
		dataRecord8.put("parentId", "2");
		dataRecord8.put("weight", "1");
		
		HashMap dataRecord9 = new HashMap();
		dataRecord9.put("id", "22");
		dataRecord9.put("text", "22");
		dataRecord9.put("parentId", "2");
		dataRecord9.put("weight", "1");
		
		HashMap dataRecord10 = new HashMap();
		dataRecord10.put("id", "31");
		dataRecord10.put("text", "31");
		dataRecord10.put("parentId", "3");
		dataRecord10.put("weight", "1");
		
		HashMap dataRecord11 = new HashMap();
		dataRecord11.put("id", "32");
		dataRecord11.put("text", "32");
		dataRecord11.put("parentId", "3");
		dataRecord11.put("weight", "1");
		
		HashMap dataRecord12 = new HashMap();
		dataRecord12.put("id", "41");
		dataRecord12.put("text", "41");
		dataRecord12.put("parentId", "4");
		dataRecord12.put("weight", "1");
		
		HashMap dataRecord13 = new HashMap();
		dataRecord13.put("id", "42");
		dataRecord13.put("text", "42");
		dataRecord13.put("parentId", "4");
		dataRecord13.put("weight", "1");
		
		HashMap dataRecord14 = new HashMap();
		dataRecord14.put("id", "43");
		dataRecord14.put("text", "43");
		dataRecord14.put("parentId", "4");
		dataRecord14.put("weight", "1");
				
		HashMap dataRecord15 = new HashMap();
		dataRecord15.put("id", "121");
		dataRecord15.put("text", "121");
		dataRecord15.put("parentId", "12");
		dataRecord15.put("weight", "1");
		
		HashMap dataRecord16 = new HashMap();
		dataRecord16.put("id", "122");
		dataRecord16.put("text", "122");
		dataRecord16.put("parentId", "12");
		dataRecord16.put("weight", "1");
		
		HashMap dataRecord17 = new HashMap();
		dataRecord17.put("id", "123");
		dataRecord17.put("text", "123");
		dataRecord17.put("parentId", "12");
		dataRecord17.put("weight", "1");
				
		HashMap dataRecord18 = new HashMap();
		dataRecord18.put("id", "321");
		dataRecord18.put("text", "321");
		dataRecord18.put("parentId", "32");
		dataRecord18.put("weight", "1");
		
		HashMap dataRecord19 = new HashMap();
		dataRecord19.put("id", "322");
		dataRecord19.put("text", "322");
		dataRecord19.put("parentId", "32");
		dataRecord19.put("weight", "1");
		
		HashMap dataRecord20 = new HashMap();
		dataRecord20.put("id", "323");
		dataRecord20.put("text", "323");
		dataRecord20.put("parentId", "32");
		dataRecord20.put("weight", "1");
				
		dataList.add(dataRecord1);
		dataList.add(dataRecord2);
		dataList.add(dataRecord3);
		dataList.add(dataRecord4);
		dataList.add(dataRecord5);
		dataList.add(dataRecord6);
		dataList.add(dataRecord7);		
		dataList.add(dataRecord8);
		dataList.add(dataRecord9);
		dataList.add(dataRecord10);
		dataList.add(dataRecord11);
		dataList.add(dataRecord12);
		dataList.add(dataRecord13);
		dataList.add(dataRecord14);		
		dataList.add(dataRecord15);
		dataList.add(dataRecord16);
		dataList.add(dataRecord17);
		dataList.add(dataRecord18);
		dataList.add(dataRecord19);
		dataList.add(dataRecord20);
		
		System.out.println(dataList.toString());
		
	}
	

}
